package com.zhangmeng.tools.languages;

import java.util.regex.Pattern;

/**
 * @author : 芊芊墨客
 * @version : 1.0
 * @date : 2023-06-01 11:01
 */
public class ProcessSql {

    public static final String[] HTMLKEYWORDS = new String[] {
            "CREATE","create", "drop", "DROP",  "INSERT","insert",
            "SELECT", "select","UPDATE","update","DELETE","delete", "FORMAT", "SUM","DATE",
            "CONSTRAINT","FOREIGN","REFERENCES","DEFAULT","NULL"
    };

    public static final String[] HTMLKEYWORDS2 = new String[] {
            "use", "IF", "if", "PRIMARY","KEY","UNIQUE", "FROM", "from","order","group","INNER","JOIN","ON","values","ALTER","SHOW","into",
            "by","INTO","VALUES","WHERE","where","SET","set","LIKE","like","UNION","ORDER","BY","GROUP","EXISTS","TABLE","table",
            "COUNT", "SUM", "AVG", "MIN", "MAX"
    };

    public static final String HTMLKEYWORDS_PATTERN = "\\b(" + String.join("|", HTMLKEYWORDS) + ")\\b";
    public static final String HTMLKEYWORDS_PATTERN2 = "\\b(" + String.join("|", HTMLKEYWORDS2) + ")\\b";
    public static final String PAREN_PATTERN = "\\(|\\)";
    public static final String BRACE_PATTERN = "\\{|\\}";
    public static final String BRACKET_PATTERN = "\\[|\\]";
    public static final String SEMICOLON_PATTERN = "\\;";
    public static final String STRING_PATTERN = "\"([^\"\\\\]|\\\\.)*\"";
    public static final String COMMENT_PATTERN = "//[^\n]*" + "|" + "/\\*(.|\\R)*?\\*/";
    public static final String ANNOTATION_PATTERN = "@[a-zA-Z]+";
    public static final String PARAMS_PATTERN = "\\\\b([a-zA-Z]+)\\\\s*=\\\\s*([a-zA-Z0-9]+)\\\\b";
    public static final String METHOD_PATTERN  = "\\w+\\((\\w+,\\s*)*\\w*\\)";

    public static final Pattern PATTERN = Pattern.compile(
            "(?<HTMLKEYWORDS>" + HTMLKEYWORDS_PATTERN + ")"
                    + "|(?<PAREN>" + PAREN_PATTERN + ")"
                    + "|(?<BRACE>" + BRACE_PATTERN + ")"
                    + "|(?<BRACKET>" + BRACKET_PATTERN + ")"
                    + "|(?<SEMICOLON>" + SEMICOLON_PATTERN + ")"
                    + "|(?<STRING>" + STRING_PATTERN + ")"
                    + "|(?<COMMENT>" + COMMENT_PATTERN + ")"
                    + "|(?<ANNOTATION>" + ANNOTATION_PATTERN + ")"
                    + "|(?<PARAMS>" + PARAMS_PATTERN + ")"
                    + "|(?<METHOD>" + METHOD_PATTERN + ")"
                    + "|(?<HTMLKEYWORDS2>" + HTMLKEYWORDS_PATTERN2 + ")"

    );
}
